package org.springblade.modules.repair.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.modules.repair.dto.BuildingSubmitDTO;
import org.springblade.modules.repair.entity.BusinessApprove;
import org.springblade.modules.repair.enums.ApproveStatusEnum;
import org.springblade.modules.repair.enums.ApproveTypeEnum;
import org.springblade.modules.repair.enums.MaintainPlanContentEnum;
import org.springblade.modules.repair.enums.TaskStatusEnum;
import org.springblade.modules.repair.service.BusinessApproveService;
import org.springblade.modules.repair.service.BusinessWorkService;
import org.springblade.modules.repair.service.IBuildingService;
import org.springblade.modules.repair.vo.BuildingSubmitVO;
import org.springblade.modules.repair.vo.BusinessApprovePageVO;
import org.springblade.modules.repair.vo.TaskStatusVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * @Date 15:09 2021/12/7
 * @Description {
 *    BusinessApproveController
 * }
 * @Author lsay
 **/
@RestController
@RequestMapping("/business/approve")
public class BusinessApproveController {

	@Autowired
	private BusinessApproveService businessApproveService;

	/**
	 * 获取审核分页列表
	 * @param businessApprove
	 * @param query
	 * @return
	 */
	@GetMapping("/page")
	public R<IPage<BusinessApprovePageVO>> page(BusinessApprove businessApprove, Query query){
		return R.data(businessApproveService.selectPage(businessApprove, Condition.getPage(query)));
	}

	/**
	 * 获取审核分类
	 * @return
	 */
	@GetMapping("/type")
	public R<?> getApproveType(){
		return R.data(ApproveTypeEnum.list());
	}

	/**
	 *  根据审核查询已提交项目信息
	 * @param businessApproveId
	 * @return
	 */
	@GetMapping("/building/detail")
	public R<HashMap<String,Object>> getApproveBuildingDetail(Long businessApproveId){
		return R.data(businessApproveService.getApproveBuildingDetail(businessApproveId));
	}

	/**
	 * 获取用户审批统计
	 * @param userId
	 * @return
	 */
	@GetMapping("/user/count")
	public R<HashMap<String,Integer>> getUserApproveCount(Long userId){
		return R.data(businessApproveService.getUserApproveCount(userId));
	}

	/**
	 * 获取审核状态
	 * @return
	 */
	@GetMapping("/status")
	public R<List<TaskStatusVO>> selectApproveStatus(){
		return R.data(ApproveStatusEnum.getTaskStatus());
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	public R update(@Valid @RequestBody BusinessApprove businessApprove) {
		businessApprove.setRemarkUpdateUser(AuthUtil.getUserId());
		return R.status(businessApproveService.updateById(businessApprove));
	}

}
